package VISTA.ventanas;

import BD.Pagoempleados;
import NEGOCIOS.ControlPagoEmpleados;
import java.awt.event.KeyEvent;
import java.beans.PropertyVetoException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import reportes.Modulos.ModuloReporteNoBD;

public class PagosDeEmpleados extends javax.swing.JInternalFrame {

    //Declaracion de variables globales
    Double pago;

    //Metodo constructor
    public PagosDeEmpleados() {
        initComponents();
        //Obtengo la fecha actual del sistema
        Date fechaSistema = new Date();
        SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy");
        //Lo muestro en la caja de texto
        jtfFecha.setText(fecha.format(fechaSistema));
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bgTipoPago = new javax.swing.ButtonGroup();
        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jtfNombre = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jtfModelo = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jtfCantidad = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jtfPrecio = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jrbPorTiempo = new javax.swing.JRadioButton();
        jrbPorTarea = new javax.swing.JRadioButton();
        jLabel8 = new javax.swing.JLabel();
        jtfFecha = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jbQuitar = new javax.swing.JButton();
        jbAgregar = new javax.swing.JButton();
        jspPagos = new javax.swing.JScrollPane();
        jtPagos = new javax.swing.JTable();
        jPanel6 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jbGuardar = new javax.swing.JButton();
        jbImprimir = new javax.swing.JButton();
        jbSalir = new javax.swing.JButton();
        jtfTotal = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setClosable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Pago de empleados");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/dollar.png"))); // NOI18N

        jPanel2.setBackground(new java.awt.Color(153, 51, 0));

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));

        jLabel2.setBackground(new java.awt.Color(102, 102, 102));
        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Nombre del empleado:");

        jtfNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtfNombreKeyTyped(evt);
            }
        });

        jLabel4.setBackground(new java.awt.Color(102, 102, 102));
        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setText("Modelo: ");

        jtfModelo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtfModeloKeyTyped(evt);
            }
        });

        jLabel5.setBackground(new java.awt.Color(102, 102, 102));
        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel5.setText("Cantidad:");

        jtfCantidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtfCantidadKeyTyped(evt);
            }
        });

        jLabel6.setBackground(new java.awt.Color(102, 102, 102));
        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setText("Precio:");

        jtfPrecio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jtfPrecioKeyTyped(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Tipo de pago"));

        bgTipoPago.add(jrbPorTiempo);
        jrbPorTiempo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jrbPorTiempo.setText("Por tiempo");
        jrbPorTiempo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jrbPorTiempoMouseClicked(evt);
            }
        });

        bgTipoPago.add(jrbPorTarea);
        jrbPorTarea.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jrbPorTarea.setSelected(true);
        jrbPorTarea.setText("Por tarea");
        jrbPorTarea.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jrbPorTareaMouseClicked(evt);
            }
        });
        jrbPorTarea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbPorTareaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jrbPorTiempo)
                .addGap(10, 10, 10)
                .addComponent(jrbPorTarea)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jrbPorTiempo, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jrbPorTarea, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel8.setBackground(new java.awt.Color(102, 102, 102));
        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setText("Fecha: ");

        jtfFecha.setEditable(false);
        jtfFecha.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jtfFecha.setForeground(new java.awt.Color(153, 51, 0));

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 371, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 32, Short.MAX_VALUE)
        );

        jbQuitar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jbQuitar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/menos.png"))); // NOI18N
        jbQuitar.setText("Quitar");
        jbQuitar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbQuitar.setPreferredSize(new java.awt.Dimension(97, 41));
        jbQuitar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbQuitarMouseClicked(evt);
            }
        });

        jbAgregar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jbAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/mas.png"))); // NOI18N
        jbAgregar.setText("Agregar");
        jbAgregar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbAgregar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbAgregarMouseClicked(evt);
            }
        });
        jbAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAgregarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbAgregar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbQuitar, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfNombre)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jtfFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtfModelo, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jtfCantidad)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jtfPrecio)
                                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jtfFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(41, 41, 41))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel4Layout.createSequentialGroup()
                                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel5)
                                        .addComponent(jLabel6))
                                    .addGap(32, 32, 32))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jtfCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtfPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jtfModelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(9, 9, 9)))
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbQuitar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel2, jLabel4, jLabel5, jLabel6, jtfCantidad, jtfModelo, jtfPrecio});

        jspPagos.setBackground(new java.awt.Color(255, 255, 255));

        jtPagos.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jtPagos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre Empleado", "Modelo", "Cantidad", "Precio", "Tipo Pago", "Total del pago"
            }
        ));
        jspPagos.setViewportView(jtPagos);
        jtPagos.getColumnModel().getColumn(0).setMinWidth(150);
        jtPagos.getColumnModel().getColumn(0).setPreferredWidth(200);
        jtPagos.getColumnModel().getColumn(1).setMinWidth(100);
        jtPagos.getColumnModel().getColumn(1).setPreferredWidth(150);
        jtPagos.getColumnModel().getColumn(2).setMinWidth(50);
        jtPagos.getColumnModel().getColumn(2).setPreferredWidth(100);
        jtPagos.getColumnModel().getColumn(3).setMinWidth(50);
        jtPagos.getColumnModel().getColumn(3).setPreferredWidth(100);
        jtPagos.getColumnModel().getColumn(4).setMinWidth(50);
        jtPagos.getColumnModel().getColumn(4).setPreferredWidth(100);
        jtPagos.getColumnModel().getColumn(5).setMinWidth(50);
        jtPagos.getColumnModel().getColumn(5).setPreferredWidth(100);

        jPanel6.setBackground(new java.awt.Color(255, 255, 255));

        jLabel9.setBackground(new java.awt.Color(102, 102, 102));
        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel9.setText("Total:");

        jbGuardar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jbGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/save.png"))); // NOI18N
        jbGuardar.setText("Guardar");
        jbGuardar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbGuardarActionPerformed(evt);
            }
        });

        jbImprimir.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jbImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/printer.png"))); // NOI18N
        jbImprimir.setText("Imprimir");
        jbImprimir.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbImprimirActionPerformed(evt);
            }
        });

        jbSalir.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jbSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/VISTA/iconos/general/Cancel.png"))); // NOI18N
        jbSalir.setText("Salir");
        jbSalir.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jbSalir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbSalirMouseClicked(evt);
            }
        });

        jtfTotal.setEditable(false);
        jtfTotal.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jtfTotal.setForeground(new java.awt.Color(153, 51, 0));
        jtfTotal.setText("0.0");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbGuardar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jtfTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel6Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jbGuardar, jbImprimir, jbSalir});

        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jbGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jtfTotal))
                .addContainerGap())
        );

        jLabel1.setBackground(new java.awt.Color(255, 204, 0));
        jLabel1.setFont(new java.awt.Font("Brush Script MT", 3, 36)); // NOI18N
        jLabel1.setText("  Pago de empleados");
        jLabel1.setOpaque(true);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jspPagos)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jspPagos, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbGuardarActionPerformed
        //Obtengo y la hago usable la fecha de los pagos
        SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy");
        //Creo el objeto de control para interactuar con la DB   
        ControlPagoEmpleados cpe = new ControlPagoEmpleados();
        //Creo la lista nesesaria para agregar los campos
        DefaultTableModel modelo = (DefaultTableModel) jtPagos.getModel();
        //Compruevo que la tabla tenga registros
        if (modelo.getRowCount() < 1) {
            JOptionPane.showMessageDialog(this, "Debe agregar por lo menos un "
                    + "pago para poder guardar.", "Error al guardar", 0);
        } else {
            List<Pagoempleados> pagos = new ArrayList<>();
            for (int i = 0; i < modelo.getRowCount(); i++) {
                Pagoempleados empleado = new Pagoempleados();
                try {
                    //Generamos el nuevo objeto que se agregara a la lista
                    empleado.setFecha(formatoFecha.parse(jtfFecha.getText()));
                    empleado.setNombre(modelo.getValueAt(i, 0).toString());
                    empleado.setModelo(modelo.getValueAt(i, 1).toString());
                    empleado.setCantidad(Integer.parseInt(modelo.getValueAt(i, 2).toString()));
                    empleado.setPrecio(Double.parseDouble(modelo.getValueAt(i, 3).toString()));
                    if (modelo.getValueAt(i, 4).toString().equals("Por Tiempo")) {
                        empleado.setTipopago("0".charAt(0));
                    } else {
                        empleado.setTipopago("1".charAt(0));
                    }
                    empleado.setTotal(Double.parseDouble(modelo.getValueAt(i, 5).toString()));
                    //Agrego a la lista el pago generado
                    pagos.add(empleado);
                } catch (ParseException | NumberFormatException ex) {
                    JOptionPane.showMessageDialog(this, "Error:" + "\n" + ex,
                            "Error al intentar guardar el pago", 0);
                }
            }
            try {
                //Guardo la lista de pagos
                cpe.agregarVariosPagosEmpleados(pagos);
                //Si todo salio bien informo al usuario
                JOptionPane.showMessageDialog(this, "Pagos guardados "
                        + "exitosamente", "Guardado", 1);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Error:" + "\n" + e,
                        "Error al intentar guardar los pagos", 0);
            }
        }
        //Llamo el metodo que borra el contenido de la tabla
        borrarContenidoTabla();
        //Reseteo el total
        jtfTotal.setText("0");
    }//GEN-LAST:event_jbGuardarActionPerformed

    private void borrarContenidoTabla() {
        //Obtengo el modelo
        DefaultTableModel modelo = (DefaultTableModel) jtPagos.getModel();
        //Borro las todas las rows
        while (modelo.getRowCount() > 0) {
            modelo.removeRow(0);
        }
    }
    private void jrbPorTiempoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jrbPorTiempoMouseClicked
        //Bloqueo los cambos cantidad y precio para evitar errores de incersion
        jtfCantidad.setEnabled(false);
        jtfPrecio.setEnabled(false);
        jtfCantidad.setText("");
        jtfPrecio.setText("");

        //Creo variable que servira para saber si todo salio bien (bandera)
        char correcto = 0;
        do {
            try {
                //Pido al usuario que teclee el monto del pago que se desea hacer
                pago = Double.parseDouble(JOptionPane.showInputDialog(this,
                        "¿Caual es el monto que devera ganar este empleado?",
                        "Teclee el pago", 3));
                if (pago > 0.0) {
                    correcto = 1;
                } else {
                    JOptionPane.showMessageDialog(this, "El empleado no puede "
                            + "recibir un pago de $0.00 o menor a $0.00.",
                            "Error al ingresar el pago", 0);
                }
            } catch (NumberFormatException e) {
                JOptionPane.showMessageDialog(this, "Solo se permiten numeros"
                        + " para escribir el monto.", "Caracteres no validos", 0);
            } catch (NullPointerException ex) {
                jrbPorTarea.doClick();
                correcto = 1;
            }
        } while (correcto == 0);

    }//GEN-LAST:event_jrbPorTiempoMouseClicked

    private void jrbPorTareaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jrbPorTareaMouseClicked
        //Activa los campos nesesarios para introducir este tipo de pago
        jtfCantidad.setEnabled(true);
        jtfPrecio.setEnabled(true);
        jtfCantidad.setText("");
        jtfPrecio.setText("");
    }//GEN-LAST:event_jrbPorTareaMouseClicked

    private void jbSalirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbSalirMouseClicked
        //Cerrar internal frame
        try {
            this.setClosed(true);
        } catch (PropertyVetoException ex) {
            this.dispose();
        }
    }//GEN-LAST:event_jbSalirMouseClicked
    private boolean verificarCamposVacios(String tipo) {
        //Verifico para que tipo de pago devo verificar los campos
        switch (tipo) {
            //Si es por tiempo verifico unicamente nombre y modelo
            case "tiempo":
                if (jtfNombre.getText().equals("") || jtfModelo.getText().equals("")) {
                    //Si alguno esta vacio 
                    return false;
                } else {
                    return true;
                }
            //Si es por tarea verifico todos los campos
            case "tarea":
                if (jtfNombre.getText().equals("") || jtfModelo.getText().equals("")
                        || jtfCantidad.getText().equals("") || jtfPrecio.getText().equals("")) {
                    return false;
                } else {
                    return true;
                }
        }
        return false;
    }

    private void jbAgregarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbAgregarMouseClicked
        //Obtengo el modelo actual de la tabla para agregar el nuevo pago
        DefaultTableModel modelo = (DefaultTableModel) jtPagos.getModel();
        //Agrego el nuevo pago
        if (jrbPorTiempo.isSelected() && verificarCamposVacios("tiempo")) {
            modelo.addRow(new String[]{jtfNombre.getText(), jtfModelo.getText(),
                "0", "0", "Por Tiempo", pago.toString()});
            generarTotal(pago);
        } else if (jrbPorTarea.isSelected() && verificarCamposVacios("tarea")) {
            Double cantidad = Double.parseDouble(jtfCantidad.getText());
            Double precio = Double.parseDouble(jtfPrecio.getText());
            Double total = cantidad * precio;
            modelo.addRow(new String[]{jtfNombre.getText(), jtfModelo.getText(),
                jtfCantidad.getText(), jtfPrecio.getText(), "Por Tarea",
                total.toString()});
            generarTotal(total);
        } else {
            JOptionPane.showMessageDialog(this, "Hay campos vacios." + "\n"
                    + "Llene todos los campos nesesarios.", "Error al agregar pago",
                    0);
            return;
        }
        //Regreso todos los campos a su valor por default
        jrbPorTarea.doClick();
        jtfCantidad.setText("");
        jtfPrecio.setText("");
        jtfNombre.setText("");
        jtfModelo.setText("");
        jtfNombre.requestFocus();
    }//GEN-LAST:event_jbAgregarMouseClicked

    private void generarTotal(Double totalPago) {
        //Genera el total de todos los pagos 
        Double total = Double.parseDouble(jtfTotal.getText());
        total += totalPago;
        jtfTotal.setText(total.toString());
    }

    private void jtfCantidadKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfCantidadKeyTyped
        //Declaracion y asignacion de valor a la variable que contendra la tecla
        //que el usuario a tecleado 
        char key = evt.getKeyChar();
        if ((key < '0' || key > '9') && (key != '\b' && (key != '\n'))) {
            evt.consume();
            JOptionPane.showMessageDialog(this, "Solo se permiten numeros en "
                    + "este campo", "Lestras no permitidas", 0);
        }
    }//GEN-LAST:event_jtfCantidadKeyTyped

    private void jtfPrecioKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfPrecioKeyTyped
        //Declaracion y asignacion de valor a la variable que contendra la tecla
        //que el usuario a tecleado 
        char key = evt.getKeyChar();
        if ((key < '0' || key > '9') && (key != '\b' && key != '\n' && key != '.')) {
            evt.consume();
            JOptionPane.showMessageDialog(this, "Solo se permiten numeros en "
                    + "este campo", "Lestras no permitidas", 0);
        }
    }//GEN-LAST:event_jtfPrecioKeyTyped

    private void jtfNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfNombreKeyTyped
        //Limitar a 40 digitos este campo
        if (jtfNombre.getText().length() > 39) {
            evt.consume();
            JOptionPane.showMessageDialog(this, "En este campo solo se permiten"
                    + ", como maximo, 40 digitos", "Cantidad de digitos exedido",
                    0);
        }
        //Restringir a que solo se permitan caracteres y no numeros
        char key = evt.getKeyChar();
        if ((key < 'a' || key > 'z') && (key < 'A' || key > 'Z') && key != 'á'
                && key != 'é' && key != 'í' && key != 'ó' && key != 'ú'
                && key != 'Á' && key != 'É' && key != 'Í' && key != 'Ó'
                && key != 'Ú' && key != '\b' && key != (char) KeyEvent.VK_SPACE) {
            evt.consume();
            JOptionPane.showMessageDialog(this, "En este campo solo se permiten"
                    + "letras.", "Numeros no permitidos",
                    0);
        }
    }//GEN-LAST:event_jtfNombreKeyTyped

    private void jtfModeloKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfModeloKeyTyped
        //Limitar a 40 digitos este campo
        if (jtfModelo.getText().length() > 39) {
            evt.consume();
            JOptionPane.showMessageDialog(this, "En este campo solo se permiten"
                    + ", como maximo 40 digitos", "Cantidad de digitos exedido",
                    0);
        }
    }//GEN-LAST:event_jtfModeloKeyTyped

    private void jbQuitarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbQuitarMouseClicked
        if (jtPagos.getSelectedRow() > -1) {
            DefaultTableModel modelo = (DefaultTableModel) jtPagos.getModel();
            Double total = Double.parseDouble(jtfTotal.getText());
            total -= Double.parseDouble(modelo.getValueAt(jtPagos.getSelectedRow(), 5).toString());
            jtfTotal.setText(total.toString());
            modelo.removeRow(jtPagos.getSelectedRow());
        } else {
            JOptionPane.showMessageDialog(this, "Seleccione un pago para poder "
                    + "quitarlo.", "Selecione un pago", 0);
        }
    }//GEN-LAST:event_jbQuitarMouseClicked

    private void jrbPorTareaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbPorTareaActionPerformed
        //Activa los campos nesesarios para introducir este tipo de pago
        jtfCantidad.setEnabled(true);
        jtfPrecio.setEnabled(true);
        jtfCantidad.setText("");
        jtfPrecio.setText("");
    }//GEN-LAST:event_jrbPorTareaActionPerformed

    private void jbImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbImprimirActionPerformed
        ModuloReporteNoBD reporteNBD = new ModuloReporteNoBD(jtPagos, "Empleados");
    }//GEN-LAST:event_jbImprimirActionPerformed

    private void jbAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAgregarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jbAgregarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bgTipoPago;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JButton jbAgregar;
    private javax.swing.JButton jbGuardar;
    private javax.swing.JButton jbImprimir;
    private javax.swing.JButton jbQuitar;
    private javax.swing.JButton jbSalir;
    private javax.swing.JRadioButton jrbPorTarea;
    private javax.swing.JRadioButton jrbPorTiempo;
    private javax.swing.JScrollPane jspPagos;
    private javax.swing.JTable jtPagos;
    private javax.swing.JTextField jtfCantidad;
    private javax.swing.JTextField jtfFecha;
    private javax.swing.JTextField jtfModelo;
    private javax.swing.JTextField jtfNombre;
    private javax.swing.JTextField jtfPrecio;
    private javax.swing.JTextField jtfTotal;
    // End of variables declaration//GEN-END:variables
}
